package com.gxl.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.gxl.pojo.UserPageInfo;
import com.gxl.service.UsersService;
import com.gxl.service.impl.UsersServiceImpl;

@WebServlet("/showuser")
public class ShowUserServlet extends HttpServlet{
	private UsersService us = new UsersServiceImpl();
	@Override
	protected void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
		int pageNumber = 1;
		String reqpageNumber = req.getParameter("pageNumber");
		if(null != reqpageNumber && reqpageNumber.length() > 0){
			pageNumber = Integer.parseInt(reqpageNumber); 
		}
		int pageSize = 2;
		String reqpageSize = req.getParameter("pageSize");
		if(null != reqpageSize && reqpageSize.length() > 0){
			pageSize = Integer.parseInt(reqpageSize); 
		}
		String name = req.getParameter("name");
		if(null != name && name.length() > 0){
			name = new String(name.getBytes("iso-8859-1"),"utf-8");
		}
		UserPageInfo userPageInfo = us.showUserList(pageNumber, pageSize, name);
		req.setAttribute("userPageInfo", userPageInfo);
		req.getRequestDispatcher("userpage.jsp").forward(req, res);
	}
	
}
